import type { SaleContractVO, SaleContractForm, SaleContractQuery } from './model';

import type { ID, IDS } from '#/api/common';
import type { PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
* 查询销售合同列表
* @param params
* @returns 销售合同列表
*/
export function saleContractList(params?: SaleContractQuery) {
  return requestClient.get<PageResult<SaleContractVO>>('/trade/saleContract/list', { params });
}

/**
 * 导出销售合同列表
 * @param params
 * @returns 销售合同列表
 */
export function saleContractExport(params?: SaleContractQuery) {
  return commonExport('/trade/saleContract/export', params ?? {});
}

/**
 * 查询销售合同详情
 * @param id id
 * @returns 销售合同详情
 */
export function saleContractInfo(id: ID) {
  return requestClient.get<SaleContractVO>(`/trade/saleContract/${id}`);
}

/**
 * 新增销售合同
 * @param data
 * @returns void
 */
export function saleContractAdd(data: SaleContractForm) {
  return requestClient.postWithMsg<void>('/trade/saleContract', data);
}

/**
 * 更新销售合同
 * @param data
 * @returns void
 */
export function saleContractUpdate(data: SaleContractForm) {
  return requestClient.putWithMsg<void>('/trade/saleContract', data);
}

/**
 * 删除销售合同
 * @param id id
 * @returns void
 */
export function saleContractRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/trade/saleContract/${id}`);
}
/**
 * 销售合同提交审核
 * @param id id
 * @returns void
 */
export function saleContractSubmit(data: IDS) {
  return requestClient.post<void>(`/trade/saleContract/submit`,data);
}

/**
 * 销售合同作废
 * @param data 包含id
 * @returns void
 */
export function saleContractInvalidate(data: { id: ID}) {
  return requestClient.postWithMsg<void>(`/trade/saleContract/invalidate`, data);
}

/**
 * 销售合同审核
 * @param id id
 * @param passed 是否通过
 * @param rejectReason 拒绝理由
 * @returns void
 */
export function saleContractApprove(id: ID, passed: boolean, rejectReason?: string) {
  return requestClient.postWithMsg<void>(`/trade/saleContract/approve`, {
    id: id,
    passed: passed,
    rejectReason: rejectReason,
  });
}
